<template>
  <el-dialog :title="info.title" :visible.sync="visible" append-to-body center width="460px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="120px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="车辆名称" prop="cart_id">
            <CartSelect v-model="form.cart_id" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="维保日期" prop="maintenance_time">
            <el-date-picker
              v-model="form.maintenance_time"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              size="small"
              clearable
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="维保类型" prop="maintenance_type">
            <el-select v-model="form.maintenance_type" size="small" style="width: 100%">
              <el-option
                v-for="item in types"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="金额" prop="money">
            <el-input v-model="form.money" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="修理保养项目" prop="remark">
            <el-input type="textarea" :rows="4" v-model="form.remark" size="small" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleEdit()">保 存</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { addMaintenance, updMaintenance } from '@/api/cart'
import CartSelect from '@/myComponents/CartSelect'
import form from '@/utils/form'

export default {
  components: { CartSelect },
  extends: form,
  props: {
    reqAdd: {
      default: addMaintenance,
      type: Function
    },
    reqUpd: {
      default: updMaintenance,
      type: Function
    }
  },
  data() {
    return {
      types: [{ key: 1, value: '维修' }, { key: 2, value: '保养' }],
      form: {},
      rules: {
        cart_id: [{ required: true, trigger: 'blur', message: '车辆名称不可为空' }],
        maintenance_time: [{ required: true, trigger: 'blur', message: '维保日期不可为空' }],
        maintenance_type: [{ required: true, trigger: 'blur', message: '维保类型不可为空' }],
        money: [{ required: true, trigger: 'blur', message: '金额不可为空' }],
        remark: [{ required: true, trigger: 'blur', message: '修理保养项目不可为空' }]
      },
      visible: false
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form = this.info.edit
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {

  }
}
</script>

<style>

</style>
